Skip to content

feat(schema): validate value constraints in --validate#71

Merged
danmrichards merged 2 commits into
mainfrom
feat/cli-numeric-validation
Jun 19, 2026
Merged

feat(schema): validate value constraints in --validate#71
danmrichards merged 2 commits into
mainfrom
feat/cli-numeric-validation

Conversation

@felixsanz

@felixsanz felixsanz commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

What

--validate was a partial validator: it enforced required and enums but silently dropped every value constraint, because the Node struct never modeled those keywords. This PR makes it validate the full JSON Schema value vocabulary the API uses, matching the SDK's AJV-based validation.

Coverage

  • Numeric: minimum, maximum, multipleOf, exclusiveMinimum, exclusiveMaximum. Non-finite values (NaN, ±Inf) on a bounded field are rejected up front, since they cannot satisfy any finite bound.
  • String: minLength, maxLength (counted in Unicode code points), pattern (RE2, and a pattern Go cannot compile is left to the server), and format for the named formats the schemas actually use (uri, uuid, date-time, email), matching the SDK's ajv-formats. Unrecognised formats pass.
  • Array: minItems, maxItems, uniqueItems.

All checks recurse through nested objects and array items, reporting the first violation with its field path. Still opt-in via --validate.

Notes

  • ValidateNumericConstraints is renamed to ValidateConstraints and dispatches by value type.
  • Addresses the Copilot review note on checkNumericBounds: NaN and Inf are now handled explicitly rather than slipping through the comparisons.

Tests

24 cases covering every keyword: violations, valid values, nested objects, array items, float multiples, NaN/Inf, exclusive bounds, each format, and the unknown-format pass-through.

Client-side --validate checked required fields and enums but silently ignored minimum, maximum, and multipleOf. The Node struct never modeled those keywords, so encoding/json dropped them on unmarshal and out-of-range values like width=-1 passed local validation and only failed server-side.

Add the three keywords to Node and a recursive ValidateNumericConstraints that checks them against payload values, descending into nested objects and array items the same way ValidateEnums does. Wire it into the validation pipeline after ValidateEnums.
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. To trigger a review, include coderabbit-review in the PR description. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Free

Run ID: 40a3d0a1-35c6-4dbe-893c-b294c176d2cd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Note

🎁 Summarized by CodeRabbit Free

Your organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the CLI’s optional --validate behavior to enforce JSON Schema numeric constraints (minimum, maximum, multipleOf) client-side, preventing out-of-range numeric payloads from reaching the API.

Changes:

  • Add Minimum, Maximum, and MultipleOf fields to internal/schema.Node so schema numeric bounds survive JSON unmarshalling.
  • Implement recursive numeric validation (ValidateNumericConstraints) for nested objects and array items, mirroring existing enum validation traversal.
  • Invoke numeric validation in the request validation pipeline (internal/api/client.go) when --validate is enabled, and add unit tests covering common bound violations and nested/array cases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
internal/schema/schema.go Models numeric bounds in Node and adds recursive numeric constraint validation helpers.
internal/schema/schema_test.go Adds test coverage for min/max/multipleOf enforcement across scalar, nested, and array-item values.
internal/api/client.go Wires numeric constraint validation into the --validate pipeline after enum validation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/schema/schema.go
Extend --validate to the rest of the JSON Schema value vocabulary the API uses: exclusiveMinimum and exclusiveMaximum, minLength, maxLength, pattern, and format (uri, uuid, date-time, email, matching the SDK ajv-formats), plus minItems, maxItems, and uniqueItems. Rename ValidateNumericConstraints to ValidateConstraints and dispatch by value type.

Non-finite numbers (NaN and Inf) on a bounded field are now rejected explicitly, which the prior numeric check would silently pass. This addresses the Copilot review note on checkNumericBounds.

All checks recurse through nested objects and array items, reporting the first violation with its field path. Still opt-in via --validate.
@felixsanz felixsanz changed the title feat(schema): enforce numeric bounds in --validate feat(schema): validate value constraints in --validate Jun 19, 2026
@danmrichards danmrichards merged commit 568c871 into main Jun 19, 2026
5 checks passed
@danmrichards danmrichards deleted the feat/cli-numeric-validation branch June 19, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants